<?php
require_once '../views/ViewAdminController.php';
require_once '../config/class.mysql.php';
require_once '../config/metadata.php';
require_once '../config/controller.php';


class AdminController extends Controller {
	
	protected static $baseUrl = '/panel/index.php';

	private  $sections = array('curriculum', 'clases', 'sehar', 'danza', 'flamenco', 'contacto');

	protected function execute() {
		if(in_array($this->func, $this->sections)) {
			if ($this->action != '_action' && is_callable(array($this, $this->action))) {
				$action = $this->action;
				$this->$action($this->func);
			} else $this->default_action($this->func);
		} else parent::execute();
	}

	private function editar_action($section){
		$errorMsg= '';
		if($_POST["seccion"]!= NULL && $_POST["texto"]!= NULL && $_POST["idioma"]!= NULL) {

			$this->Mysql->update(table, array($_POST["seccion"] => $_POST["texto"]), "idioma='".$_POST['idioma']."'");
			
		}
		else $errorMsg = '1';

		$this->redirect($section, $errorMsg);
	}

	private function default_action($section){
		$metadata = Metadata::get($section);
		
		$result = $this->Mysql->getWhere('contenido', $section, array('idioma', $this->idioma));
		$data = array(
			'title' =>  $metadata['title'], 
			$section => $result[0][$section], 
			'seccion' => $section,
			'idioma' => $this->idioma,
			'error' => (isset($_GET['error']) ? 1 : '')
		);
		$this->viewController->render('default', $data, $metadata);
	}

}

$controller = new AdminController('viewAdminController', true);
$controller->dispatch();
